package com.example.onion.hxchat.thread;

import android.graphics.Bitmap;
import android.os.Handler;
import android.os.Message;


import com.example.onion.hxchat.util.ImgDownUtil;

import java.io.IOException;


/**
 * @author:onion
 * @data: 2020/8/22
 */
public class PlayUserImg implements Runnable{




    private Handler mHandler;
    public static final int PLAYIMG_IS_FINISH = 6;
    public static final int PLAYIMG_IS_FAILED = 5;

    private String url ;
    /**
     * 构造方法，传入需要显示图片的url
     * @param url
     */
    public PlayUserImg(String url,Handler handler) {
        this.url = url;
        this.mHandler = handler;
    }

    @Override
    public void run() {
        try{
            Bitmap bitmap = ImgDownUtil.Bytes2Bimap(ImgDownUtil.getImageBytes(url));
            Message msg = Message.obtain();
            msg.obj = bitmap;
            msg.what = PLAYIMG_IS_FINISH;
            mHandler.sendMessage(msg);
        } catch (IOException e) {
            Message msg = Message.obtain();
            msg.obj = null;
            msg.what = PLAYIMG_IS_FAILED;
            mHandler.sendMessage(msg);
            e.printStackTrace();
        }
    }
}
